// miniprogram/devTools/wanandroid/wanandroid.js
import {
  article
} from "../../router"
Page({

  data: {
    wxArticleMenus: []
  },
  onLoad: function (options) {
    this.getArticleMenus()
  },
  onShareAppMessage: function () {

  },
  getArticleMenus() {
    wx.showLoading({
      title: '加载中',
    })
    wx.cloud.callFunction({
      name: 'wanandroid',
      data: {
        action: "chapters",
        pageNum: '1'
      }
    }).then(res => {
      wx.hideLoading()
      console.log(res)
      let wxArticleMenus = res.result.data
      this.setData({
        wxArticleMenus
      })
    }).catch(err => {
      wx.hideLoading()
      console.error(err)
    })
  },
  onMenuClick(e) {
    console.log(e)
    let menuItem = e.currentTarget.dataset.menu
    wx.navigateTo({
      url: article + `?menuId=${menuItem.id}&menuName=${menuItem.name}`
    })
  }
})